import React, {useEffect} from 'react';
import {ModalFormProps} from "../../../Components/formTable/type";
import {queryStationList,saveStation} from "./station.service";
import {Form, Input, InputNumber, message, Modal} from "antd";
import {useModalFormAction,singleColumnLayout} from "../../../Components/formTable/form";

const FormItem = Form.Item;

interface PositionEditProps extends ModalFormProps{
    deptId:string;
}
const FormItemInfo = ({label,name,msg,info,type='input'}:{label:string,name:string, msg?:string,type?:string,info:any})=>{
  return (
    <FormItem label={label} name={name} rules={msg?[{required: true, message: '岗位代码 不能为空'}] :[]}>
      {type==='input'&&<Input/>}
      {type==='number'&&<InputNumber/>}
      {type==='checkbox'&&<Input/>}
      {type==='select'&&<Input/>}
      {type==='password'&&<Input/>}
      {type==='date'&&<Input/>}
      {type==='time'&&<Input/>}
      {type==='datetime'&&<Input/>}
      {type==='daterange'&&<Input/>}
    </FormItem>
  )
}
export default function({id,visible,onCancel,onOk, title,deptId}:PositionEditProps){


    const {form,onCommit, } = useModalFormAction(queryStationList,saveStation, onOk, id);

    return <Modal visible={visible} onCancel={onCancel} onOk={onCommit} width={500} title={title}>
        <Form form={form} {...singleColumnLayout} scrollToFirstError={true}>
            <FormItem label={'岗位代码'} name='code' rules={[{required: true, message: '岗位代码 不能为空'}]}>
                <Input/>
            </FormItem>
            <FormItem label={"岗位名称"} name='name' rules={[{required: true, message: '岗位名称 不能为空'}]}>
                <Input/>
            </FormItem>
            <FormItem label={'备注'} name='remark'  >
                <InputNumber/>
            </FormItem>
            <FormItem label={'归属部门'} name={'remark'}  >
                <Input/>
            </FormItem>
        </Form>
    </Modal>;
}
// useEffect(()=>{
//     if(id){
//         queryDictById(id).then(e=>{
//             form.setFieldsValue(e);
//         }) ;
//     }
//
// },[id]);
//
// // const [form] =Form.useForm();
//
// const onCommit = ()=>{
//     let errors= form.getFieldsError();
//     if(errors.length){
//         // TODO 处理好 提醒
//         return message.warn("请按要求填写");
//     }
//     let data = form.getFieldsValue();
//     if(id){
//         data = {...data, id};
//     }
// };
